//
//  PublishDateCtrl.m
//  laowu
//
//  Created by Northwan on 15/5/8.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "PublishDateCtrl.h"
#import "PublishDateCell.h"
#import "PublishDateModel.h"

@interface PublishDateCtrl ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(strong,nonatomic)NSMutableArray *dateArray;
@end

@implementation PublishDateCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"选择发布日期"];
    [self initTableViewWithDateArr];
}

-(void)initTableViewWithDateArr{
    _dateArray = [NSMutableArray array];
    
    PublishDateModel *dateBean = [[PublishDateModel alloc]init];
    [dateBean setDate_id:ALL_DAY];
    [dateBean setDateText:@"所有日期"];
    [_dateArray addObject:dateBean];
    
    PublishDateModel *dateBean1 = [[PublishDateModel alloc]init];
    [dateBean1 setDate_id:ONE_DAY];
    [dateBean1 setDateText:@"近一天"];
    [_dateArray addObject:dateBean1];
    
    PublishDateModel *dateBean2 = [[PublishDateModel alloc]init];
    [dateBean2 setDate_id:TWO_DAY];
    [dateBean2 setDateText:@"近两天"];
    [_dateArray addObject:dateBean2];
    
    PublishDateModel *dateBean3 = [[PublishDateModel alloc]init];
    [dateBean3 setDate_id:THREE_DAY];
    [dateBean3 setDateText:@"近三天"];
    [_dateArray addObject:dateBean3];
    
    PublishDateModel *dateBean4 = [[PublishDateModel alloc]init];
    [dateBean4 setDate_id:FORE_DAY];
    [dateBean4 setDateText:@"近四天"];
    [_dateArray addObject:dateBean4];
    
    PublishDateModel *dateBean5 = [[PublishDateModel alloc]init];
    [dateBean5 setDate_id:ONE_WEEK];
    [dateBean5 setDateText:@"近一周"];
    [_dateArray addObject:dateBean5];
    
    PublishDateModel *dateBean6 = [[PublishDateModel alloc]init];
    [dateBean6 setDate_id:TWO_WEEK];
    [dateBean6 setDateText:@"近两周"];
    [_dateArray addObject:dateBean6];
    
    PublishDateModel *dateBean7 = [[PublishDateModel alloc]init];
    [dateBean7 setDate_id:ONE_MONTH];
    [dateBean7 setDateText:@"近一个月"];
    [_dateArray addObject:dateBean7];
    
    PublishDateModel *dateBean8 = [[PublishDateModel alloc]init];
    [dateBean8 setDate_id:ONE_MONTH];
    [dateBean8 setDateText:@"近两个月"];
    [_dateArray addObject:dateBean8];
    
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    [_tableView setTableFooterView:[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 0)]];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dateArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PublishDateCell *cell = [PublishDateCell cellWithTableView:tableView indexPath:indexPath];
    [cell initData:[_dateArray[indexPath.row] dateText]];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return PublishDateCellHeight;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [[NSNotificationCenter defaultCenter]postNotificationName:nortif_date_choose_finish object:_dateArray[indexPath.row]];
    [self.navigationController popViewControllerAnimated:YES];
}

@end
